package com.example.swim;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity2 extends AppCompatActivity {
private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
        Intent intent=getIntent();
        String url=intent.getStringExtra("url=");
        String title = intent.getStringExtra("title");
        String time = intent.getStringExtra("time");
        String content = intent.getStringExtra("content");
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
        if (url!=null){
            webView.loadUrl(url);
        }
        if (title!=null&time!=null&content!=null){
            webView.loadDataWithBaseURL(null,title+"      "+time+"\n"+content,"text/html", "utf-8",null);

        }
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//显示返回键（Display显示Enabled启用）
        getSupportActionBar().setHomeButtonEnabled(true);//设置返回键

    }
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        finish();
        return super.onOptionsItemSelected(item);
    }

    private void initView() {
        webView = (WebView) findViewById(R.id.wed_view);
    }
}